package com.kyw.android_dev_util.controller;

import com.kyw.android_dev_util.common.ConstField;
import com.kyw.android_dev_util.common.MessageConstant;
import com.kyw.android_dev_util.common.ResResult;
import com.kyw.android_dev_util.res.UserInfo;
import com.kyw.android_dev_util.res.pc.FileBean;
import com.kyw.android_dev_util.service.FileService;
import com.kyw.android_dev_util.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import sun.security.krb5.internal.PAData;

import java.io.File;
import java.io.IOException;
import java.util.List;

@RestController
@CrossOrigin
public class FileController {
    @Autowired
    FileService fileService;
    @GetMapping(value = "/test")
    public ResResult test( String projectPath){
      /*  ApplicationHome home = new ApplicationHome(getClass());
        File jarFile = home.getSource();
        System.out.println(jarFile.getParentFile().getAbsolutePath());*/
        FileUtil fileUtil = new FileUtil();
        fileUtil.getFile();
        return new ResResult(MessageConstant.ACCESS_OK);
    }
    @GetMapping(value = "/getLayoutFiles")
    public ResResult getLayoutFiles(){
        List<FileBean> files = fileService.getFile(ConstField.LAYOUT_PATH, false);
        return new ResResult(MessageConstant.ACCESS_OK,files);
    }
    @GetMapping(value = "/showCodeFiles")
    public ResResult showCodeFiles(String codePath){
        List<FileBean> files = fileService.getFile(codePath, false);
        return new ResResult(MessageConstant.ACCESS_OK,files);
    }
    @GetMapping(value = "/createLinearLayout")
    public ResResult createLinearLayout( String fileName){
        FileUtil fileUtil = new FileUtil();
        fileUtil.createLinearLayout(fileName);
        return new ResResult(MessageConstant.ACCESS_OK);
    }
    @GetMapping(value = "/updateIdToCode")
    public ResResult updateIdToCode( String layoutPath,String codePath) throws IOException {
            fileService.updateIdToCode(layoutPath,codePath);
        return new ResResult(MessageConstant.ACCESS_OK);
    }
}
